package com.sneakxy.mybase4j.platform.repository;

import java.util.List;

import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.sneakxy.mybase4j.base.repository.BaseRepository;
import com.sneakxy.mybase4j.platform.beans.Menu;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Repository
public interface MenuRepository extends BaseRepository<Menu, String> {

	@Select({
		"select m.* from t_mb4j_menu m",
		"left join t_mb4j_router r on m.router = r.name",
		"where (r.perm_id in (select perm_id from t_mb4j_role_perm rp",
		"left join t_mb4j_account_role ar on ar.role_id=rp.role_id ",
		"where ar.account_id=#{account_id}) or r.perm_id is null)",
		"and m.type=#{type}",
		"order by m.sort"})
	@ResultMap("Menu")
	public List<Menu> findByAccountId(@Param("account_id") String account_id, @Param("type") String type);
	
	@Select({
		"select m.* from t_mb4j_menu m",
		"where m.type=#{type}",
		"order by m.sort"})
	@ResultMap("Menu")
	public List<Menu> findByType(@Param("type") String type);
	
}
